<?php
namespace My\Controller;
use Utuo\BackgroundController;
class MicroVoteRecordController extends  BackgroundController
 { private $micro_vote_id;  
   private  $status = array(
			'0' => '未审核',
			'1' => '已通过',
			'2' => '未通过',
	);
	public function _initialize() {
		$this->micro_vote_id=I('micro_vote_id',0,'intval');
		$this->setControllerTitle("投票人信息管理");
		$this->setActionTitle(array(
			'index' => '投票人信息列表',
			'recycle' => '回收站'
		),null,array('micro_vote_id'=>$this->micro_vote_id));
		$this->setActionNav(array(
			'index',
			
			'recycle'
		));
	}
	public function getLists($is_deleted){
		$condation=array(
			'r.is_deleted'=>$is_deleted,
			'r.micro_vote_id'=>$this->micro_vote_id,	
			'v.status'=>1,
			'v.is_deleted'=>0,
			'r.cid'=>$this->aid,			
		);
		$m=M('MicroVoteRecord r');
		$microVoteRecord=$m->join("__MICRO_VOTE__ v ON r.micro_vote_id=v.id")->join('__MICRO_VOTE_ITEM__ i on i.id=r.selected')->where($condation)->order('id desc')->page($this->getPage(),$this->getPageSize())->field('r.*,v.title as microVoteTitle,i.title as itemTitle')->select();
		
		foreach ( $microVoteRecord as $k => &$v ) {
			$title="";
			$v ['statusOptions'] = \Utuo\Form::getOption ($this->status, $v ['status'] );
			
		}
        $total=$m->join("__MICRO_VOTE__ v ON r.micro_vote_id=v.id")->where($condation)->distinct('r.id')->count();
		$this->showPage($total, $this->getPageSize());
		$this->assign("microVoteRecord",$microVoteRecord);
		$this->display();
		
	}
	public function setStatusAction() {
		$id = I ( "id", 0, "intval" );
		$status = I ( "status", 0, "intval" );
		$d = D ( "MicroVoteRecord" );
		if ($d->where ( "id={$id}" )->setField ( "status", $status )) {
			$this->ajaxSuccess ();
		} else {
			$this->ajaxError ( $d->getError () );
		}
	}
}